package com.huawei.dli.flink.sye.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Hive client info.
 */
public class HiveClientInfo {
  //The zk quorum info, format like: ip1:port,ip2:port...
  private String zkQuorum = null;
  private String auth = null;
  private String saslQop = null;
  private String zooKeeperNamespace = null;
  private String serviceDiscoveryMode = null;
  private String principal = null;

  private Properties clientInfo = null;

  public HiveClientInfo(String hiveClientFile) throws IOException {
    InputStream fileInputStream = null;
    try {
      clientInfo = new Properties();
      fileInputStream = this.getClass().getResourceAsStream("/" + hiveClientFile);
      clientInfo.load(fileInputStream);
    } catch (Exception e) {
      throw new IOException(e);
    } finally {
      if (fileInputStream != null) {
        fileInputStream.close();
      }
    }
    initialize();
  }

  private void initialize() {
    zkQuorum = clientInfo.getProperty("zk.quorum");
    auth = clientInfo.getProperty("auth");
    saslQop = clientInfo.getProperty("sasl.qop");
    zooKeeperNamespace = clientInfo.getProperty("zooKeeperNamespace");
    serviceDiscoveryMode = clientInfo.getProperty("serviceDiscoveryMode");
    principal = clientInfo.getProperty("principal");
  }

  public String getZkQuorum() {
    return zkQuorum;
  }

  public String getSaslQop() {
    return saslQop;
  }

  public String getAuth() {
    return auth;
  }

  public String getZooKeeperNamespace() {
    return zooKeeperNamespace;
  }

  public String getServiceDiscoveryMode() {
    return serviceDiscoveryMode;
  }

  public String getPrincipal() {
    return principal;
  }
}
